import Control.Controller;
import Control.GroupGenerator;
import Game.*;

public class tests {
/*
    protected static void showBlock(Block b){
        System.out.println("("+Integer.toString(b.position.getX()) + ","+Integer.toString(b.position.getY())+")");
    }

    protected static void showGroup (Group g){
        int len = g.blocks.size();
        boolean [][] map = new boolean[5][5];
        for (Block block : g.blocks){
            map
                    [block.position.getX() + g.position.getX() + 2]
                    [block.position.getY() + g.position.getY() + 2]
                    = true ;
        }

        for (int y = 0 ; y < 5  ; y ++){
            for (int x = 0; x < 5 ; x++){
                if (map[x][y]){
                    System.out.print("o ");
                }else {
                    System.out.print("* ");
                }
            }
            System.out.println();
        }
        System.out.println();
    }
//    public static void Rotate() {
//        Game.Group g = new Game.Group();
////        g = new Game.Group();
//        g.blocks = new Game.Block[3];
//        g.blocks[0] = new Game.Block(-1,0);
//        g.blocks[1] = new Game.Block(0,0);
//        g.blocks[2] = new Game.Block(1,0);
//        g.rotate();
//        showGroup(g);
//    }

    public static void _Rotate(Group g){
        g.rotate();
        showGroup(g);
        System.out.println();
    }

    public static void GropGener(){
//        System.out.println(
//                Control.GroupGenerator.generateOGroup().blocks.length
//        );
        Group g = GroupGenerator.generateTGroup(0,0);
        _Rotate(g);
        _Rotate(g);
        _Rotate(g);
        g.move(ActionType.UP);
        g.move(ActionType.RIGHT);
        _Rotate(g);
    }

    protected static void CtrlTest () throws Exception {
        Group g = GroupGenerator.generateIGroup(0,0);
        Controller ctrl = new Controller();
        while (true){
            showGroup(g);
            ctrl.recieve();
            ActionType dir = ActionType.ROTATE;
            try{
                dir = ctrl.out();
                System.out.println(ctrl.cmd);
                if (dir == ActionType.ROTATE){
                    g.rotate();
                }else{
                    g.move(dir);
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

    protected static void showBox (GameBox gameBox){
        for (int y = 0 ; y < gameBox.getHeight() ; y ++){
            for (int x = 0 ; x < gameBox.getWidth() ; x ++){
                if (gameBox.tags[x][y] == 0){
                    System.out.print("* ");
                }else{
                    System.out.print("O ");
                }

            }
            System.out.println();
        }
    }

    protected static void showBox_Group(GameBox gameBox , Group group){
        for (int y = 0 ; y < gameBox.getHeight() ; y ++){
            for (int x = 0 ; x < gameBox.getWidth() ; x ++){
                boolean tag = false ;

                for (Block block : group.blocks){
                    if (x == block.position.getX() + group.position.getX()){
                        if (y == block.position.getY() + group.position.getY()){
                            tag = true ;
                            System.out.print("O ");
                        }
                    }
                }
                if (tag) continue;

                if (gameBox.tags[x][y] == 0){
                    System.out.print("* ");
                }else{
                    System.out.print("O ");
                }

            }
            System.out.println();
        }
    }

    protected static void CoincidenceTest() throws Exception {
        Game.GameBox gameBox = new Game.GameBox(10,10);
        for (int y = 8 ; y < 10 ; y ++){
            for (int x = 0 ; x < 10 ; x ++){
                gameBox.tags[x][y] = 1 ;
            }
        }
        Game.Group group = Control.GroupGenerator.generateTGroup(5,5);

        Control.Controller ctrl = new Control.Controller();
        showBox(gameBox);
        while (true){
            ctrl.recieve();
            try {
                Game.ActionType action = ctrl.out();
                System.out.println(action.toString());

                group.move(action);

//                for (Game.Block block : group.blocks){
//                    int x = block.position.getX() + group.position.getX();
//                    int y = block.position.getY() + group.position.getY();
//
//                    System.out.println("Logic   :\t"+Integer.toString(block.position.getX() ) + '\t' + Integer.toString(block.position.getY()));
//                    System.out.println("Offset  :\t"+Integer.toString(group.position.getX()) + '\t' + Integer.toString(group.position.getX()));
//                    System.out.println("Physical:\t"+Integer.toString(x) + '\t' + Integer.toString(y));
//                    System.out.println();
//                }


                if (Game.CollisionDetector.isConcided(gameBox , group)){
                    //showBox(gameBox);
                    group.move(Game.ActionType.getInverse(action));
                    showBox_Group(gameBox , group);
                }else{
                    showBox_Group(gameBox , group);
                }

            }catch (Exception e){
                e.printStackTrace();
            }

        }


    }

    protected static void StrandedTest() throws InterruptedException {
        Game.GameBox gameBox = new Game.GameBox(10,10);
        Game.Group group = Control.GroupGenerator.generateIGroup(1,0);
        do{
            showBox_Group(gameBox,group);
            group.move(Game.ActionType.DOWN);
            System.out.println();
            System.out.println();
            Thread.sleep(1000);
        }while (!Game.CollisionDetector.isConcided(gameBox,group));
        gameBox.place(group);
        showBox(gameBox);
    }

    public static void GroupClone () throws CloneNotSupportedException {
        Group g1 = new Group();
        g1.blocks.add(new Block(1,0));
        Group g2 = g1.clone();
        System.out.println(g1.blocks.get(0).position.getY());
        System.out.println(g2.blocks.get(0).position.getY());

        g2.rotate();
        System.out.println(g1.blocks.get(0).position.getY());
        System.out.println(g2.blocks.get(0).position.getY());

        g2.move(ActionType.DOWN);
        System.out.println(g1.position.getY());
        System.out.println(g2.position.getY());
    }

    public static void CollisionTest() throws InterruptedException, CloneNotSupportedException {
        GameBox gameBox = new GameBox(10,10);
        Group group = GroupGenerator.generateIGroup(1,0);

        showBox_Group(gameBox,group);
        System.out.println();
        System.out.println();
        while (!CollisionDetector.crashed(gameBox,group,ActionType.DOWN)){
            if(CollisionDetector.crashed(gameBox,group,ActionType.DOWN)){
                System.out.println("Will crashed!");
            }
            showBox_Group(gameBox,group);
            group.move(ActionType.DOWN);
//            System.out.println(group.position.getX());
//            System.out.println(group.position.getY());
            System.out.println();
            System.out.println();
            Thread.sleep(1000);
        }

//        System.out.println(group.position.getX());
//        System.out.println(group.position.getY());
        gameBox.place(group);
        showBox(gameBox);
    }

    protected static void Ctrl_Collision_Test() throws Exception {
        GameBox gameBox = new GameBox(10,10);


        Controller ctrl = new Controller();
//        showBox(gameBox);
        Group group = GroupGenerator.generateZGroup(1,0);
        showBox_Group(gameBox , group);
        while (true){
            ctrl.recieve();
            try {
                ActionType action = ctrl.out();
                System.out.println(action.toString());


//                for (Game.Block block : group.blocks){
//                    int x = block.position.getX() + group.position.getX();
//                    int y = block.position.getY() + group.position.getY();
//
//                    System.out.println("Logic   :\t"+Integer.toString(block.position.getX() ) + '\t' + Integer.toString(block.position.getY()));
//                    System.out.println("Offset  :\t"+Integer.toString(group.position.getX()) + '\t' + Integer.toString(group.position.getX()));
//                    System.out.println("Physical:\t"+Integer.toString(x) + '\t' + Integer.toString(y));
//                    System.out.println();
//                }


                if (CollisionDetector.crashed(gameBox , group,action)){
                    showBox_Group(gameBox , group);
                    continue;
                }else{
                    group.move(action);
                }
                showBox_Group(gameBox , group);
            }catch (Exception e){
                e.printStackTrace();
            }

            if (CollisionDetector.stranded(gameBox,group)){
                System.out.println("stranded");
                gameBox.place(group);
                break;
            }

        }


        group = GroupGenerator.generateIGroup(1,0);
        showBox_Group(gameBox , group);
        while (true){
            ctrl.recieve();
            try {
                ActionType action = ctrl.out();
                System.out.println(action.toString());


//                for (Game.Block block : group.blocks){
//                    int x = block.position.getX() + group.position.getX();
//                    int y = block.position.getY() + group.position.getY();
//
//                    System.out.println("Logic   :\t"+Integer.toString(block.position.getX() ) + '\t' + Integer.toString(block.position.getY()));
//                    System.out.println("Offset  :\t"+Integer.toString(group.position.getX()) + '\t' + Integer.toString(group.position.getX()));
//                    System.out.println("Physical:\t"+Integer.toString(x) + '\t' + Integer.toString(y));
//                    System.out.println();
//                }


                if (CollisionDetector.crashed(gameBox , group,action)){
                    showBox_Group(gameBox , group);
                    continue;
                }else{
                    group.move(action);
                }
                showBox_Group(gameBox , group);
            }catch (Exception e){
                e.printStackTrace();
            }
            if (CollisionDetector.stranded(gameBox,group)){
                System.out.println("stranded");
                gameBox.place(group);
                break;
            }

        }

    }
    public static void main(String[]args) throws Exception {
//        Control.Controller.test();
//        GropGener();
//        CtrlTest();
//        CoincidenceTest();
//        StrandedTest();
//        GroupClone();
//          CollisionTest();
        Ctrl_Collision_Test();
    }
*/
}

